package com.sxjh.controller.cb;

import com.sxjh.common.BaseController;
import com.sxjh.config.Authorization;
import com.sxjh.common.Result;
import com.sxjh.config.ExcelCacheConfig;
import com.sxjh.entity.ExcelEntity;
import com.sxjh.entity.param.*;
import com.sxjh.entity.result.*;
import com.sxjh.service.ExcelService;
import com.sxjh.service.FinanceService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;

/**
 * 甲醇厂财务结算报表
 */
@RestController
@Api(tags = "甲醇厂")
@RequestMapping("/methyl-alcohol")
public class Finance8Controller extends BaseController {

  @Autowired
  private FinanceService financeService;

  @Autowired
  private ExcelService excelService;

  @ApiOperation("甲醇")
  @GetMapping("/jc")
  @Authorization("cb.methyl-alcohol.jc")
  Result<List<Finance8Result>> list(@Validated Finance8Param param) {
    param.setMaterialId(17);
    List<Finance8Result> list = financeService.list21(param);
    return Result.ok(list);
  }

  @ApiOperation("甲醇Excel导出")
  @GetMapping("/jc/excel")
  @Authorization("cb.methyl-alcohol.jc")
  Result<String> listExcel(@Validated Finance8Param param) {
    String id = ExcelCacheConfig.setParam(param, ExcelEntity.Type.JC);
    return ok(id);
  }

  @ApiOperation("甲醇明细")
  @GetMapping("/jc-mx")
  @Authorization("cb.methyl-alcohol.jc-mx")
  Result<List<Finance8List4Result>> list4(@Validated Finance8List4Param param) {
    List<Finance8List4Result> list = financeService.list25(param);
    return Result.ok(list);
  }
  @GetMapping("/jc-cd")
  @ApiOperation("甲醇拆单")
  @Authorization("cb.chemical-big.jc-cd")
  Result<Void> jcCd(@Validated Finance25JcCd param) {
    try {
      financeService.jctear(param);
    } catch (RuntimeException e) {
      return err(e.getMessage());
    }
    return ok();
  }
  @ApiOperation("甲醇明细Excel导出")
  @GetMapping("/jc-mx/excel")
  @Authorization("cb.methyl-alcohol.jc-mx")
  Result<String> listExcel(@Validated Finance8List4Param param) {
    String id = ExcelCacheConfig.setParam(param, ExcelEntity.Type.JC_MX);
    return ok(id);
  }

  @ApiOperation("杂醇")
  @GetMapping("/zc")
  @Authorization("cb.methyl-alcohol.zc")
  Result<List<Finance8List2Result>> list2(@Validated Finance8Param param) {
    param.setMaterialId(18);
    List<Finance8List2Result> list = financeService.list22(param);
    return Result.ok(list);
  }

  @ApiOperation("化产脱硫副盐")
  @GetMapping("/fy")
  @Authorization("cb.methyl-alcohol.fy")
  Result<List<Finance8Result>> fy(@Validated Finance8Param param) {
    param.setMaterialId(19);
    List<Finance8Result> list = financeService.list21(param);
    return Result.ok(list);
  }

  @ApiOperation("甲醇火车")
  @GetMapping("/jc-hc")
  @Authorization("cb.methyl-alcohol.jc-hc")
  Result<List<Finance8List3Result>> list3(@Validated Finance8List3Param param) {
    List<Finance8List3Result> list = financeService.list24(param);
    return Result.ok(list);
  }
  @ApiOperation("杂醇销售对账开票")
  @GetMapping("/zc-xs-dz-kp")
//  @Authorization("cb.methyl-alcohol.zc")
  Result<List<Finance4KhXsResult>> list44(@Validated Finance8Param param) {
    param.setMaterialId(18);
    List<Finance4KhXsResult> list = financeService.list34(param);
    return Result.ok(list);
  }
}
